package com.yaha.controler.devices.search;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.IBinder;

import com.yaha.controler.devices.WifiBroadcastReceiver;
import com.yaha.controler.utils.MyLog;

/**
 * <功能描述>设备发现服务
 * 
 * @author Frewen.W/909091
 * @version [版本号, 2015-4-9]
 * @since [产品/模块版本]
 */
public class DeviceSearchService extends Service {
	private static final String TAG = DeviceSearchService.class.getSimpleName();
	private WifiBroadcastReceiver wifiBroadcastReceiver;

	@Override
	public void onCreate() {
		MyLog.i(TAG, "DeviceSearchService onCreate-->Begin");
		initWifiBroadCast();
		super.onCreate();
	}

	private void initWifiBroadCast() {
		// wifi切换广播
		IntentFilter intentFilter = new IntentFilter();
		intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
		intentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);

		wifiBroadcastReceiver = new WifiBroadcastReceiver();
		registerReceiver(wifiBroadcastReceiver, intentFilter);
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	public void onDestroy() {
		if (null != wifiBroadcastReceiver) {
			unregisterReceiver(wifiBroadcastReceiver);
		}
	}
}
